package com.ruoyi.common.utils.page;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

public class Condition {

    public static <T>IPage<T> getPage(Query query){
        Page<T> page=new Page<>(1,10);
        if (query.getCurrent()!=null||query.getSize()!=null){
            page.setCurrent(query.getCurrent()).setSize(query.getSize());
            if ("asc".equals(query.getOrder())){
                page.addOrder(OrderItem.asc(query.getOrder()));
            } else if ("desc".equals(query.getOrder())) {
                page.addOrder(OrderItem.desc(query.getOrder()));
            }
        }
        return page;
    }

    public static <T>QueryWrapper<T> getQueryWrapper(T entity){
        return new QueryWrapper<>(entity);
    }
}
